<template>
	<view class="feedback-detail-container">

		<!-- 自定义导航栏 -->
		<u-navbar placeholder safeAreaInsetTop @leftClick='leftClick' title="反馈详情"
			titleStyle='font-weight:bold;font-size:32rpx' :autoBack="false"></u-navbar>

		<!-- 内容区域 -->
		<view class="detail-content" v-if="detail">
			<!-- 标签和日期 -->
			<view class="header-info">
				<view class="header-tag" :class="typeClass">{{getTypeName(detail.type)}}</view>
				<view class="header-date">发布于 {{formatDate(detail.create_time)}}</view>
			</view>

			<!-- 标题 -->
			<view class="content-title">{{detail.title}}</view>

			<!-- 用户信息 -->
			<view class="user-info">
				<image class="user-avatar" :src="detail.card.avatar || ''" mode="aspectFill"></image>
				<view class="user-details">
					<view class="user-name">{{detail.card.name || ''}}</view>
					<view class="user-company">{{detail.card.position.company_name || ''}}</view>
				</view>
				<view v-if="detail.money" class="money-tag">
					<text class="money-icon">¥</text>
					<text class="money-value">{{formatMoney(detail.money)}}</text>
				</view>
			</view>

			<!-- 描述内容 -->
			<view class="content-desc">
				<text>{{detail.content}}</text>
			</view>

			<!-- 图片展示 - 纵向排列 -->
			<view class="image-gallery" v-if="images.length > 0">
				<view v-for="(item, index) in images" :key="index" class="image-item">
					<image :src="item" mode="widthFix" @click="previewImage(index)" class="gallery-image"></image>
				</view>
			</view>

			<!-- 建议/愿景 -->
			<view v-if="detail.suggest" class="suggestion-section">
				<view class="suggestion-title">
					<view class="suggestion-line"></view>
					<text>愿景与建议</text>
					<view class="suggestion-line"></view>
				</view>
				<view class="suggestion-content">{{detail.suggest}}</view>
			</view>
		</view>

		<!-- 加载状态 -->
		<view class="loading-container" v-if="!detail">
			<view class="loading-text">数据加载中...</view>
		</view>

		<!-- 底部间距 -->
		<view style="height: 50rpx;"></view>
	</view>
</template>

<script>
	import {
		PlatformFeedBackDetail
	} from "@/api/extend.js"

	export default {
		data() {
			return {
				id: null,
				typeClass: 'header-tag-blue',
				images: [],
				detail: null,
				typeMap: {
					1: {
						name: '沙龙收获',
						class: 'header-tag-blue'
					},
					2: {
						name: '合作反馈',
						class: 'header-tag-red'
					},
					3: {
						name: '贵商寄语',
						class: 'header-tag-green'
					},
					4: {
						name: '项目合作',
						class: 'header-tag-orange'
					},
				}
			}
		},
		onLoad(options) {
			if (options.id) {
				this.id = options.id;
				// 获取详情数据
				this.loadDetail();
			} else {
				uni.showToast({
					title: '参数错误',
					icon: 'none'
				})
				setTimeout(() => {
					uni.navigateBack()
				}, 1500)
			}
		},
		methods: {
			leftClick() {
				uni.redirectTo({
					url: '/pages/extend/index/index_feedback'
				})

			},
			loadDetail() {
				uni.showLoading({
					title: '加载中'
				})

				PlatformFeedBackDetail({
					id: this.id
				}).then(res => {
					if (res.data) {
						this.detail = res.data
						// 解析图片
						if (this.detail.images) {
							this.images = this.detail.images.split(',')
						}
						// 设置类型样式
						this.setTypeClass()
					} else {
						uni.showToast({
							title: '获取详情失败',
							icon: 'none'
						})
					}
					uni.hideLoading()
				}).catch(() => {
					uni.hideLoading()
					uni.showToast({
						title: '获取详情失败',
						icon: 'none'
					})
				})
			},
			// 获取类型名称
			getTypeName(type) {
				return this.typeMap[type]?.name || '其他'
			},
			// 格式化日期
			formatDate(dateStr) {
				if (!dateStr) return ''
				const date = new Date(dateStr)
				return `${date.getFullYear()}/${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')}`
			},
			// 格式化金额
			formatMoney(money) {
				if (!money) return '0'
				if (money >= 10000) {
					return (money / 10000).toFixed(0) + '万'
				}
				return money
			},
			setTypeClass() {
				// 根据类型设置样式
				this.typeClass = this.typeMap[this.detail.type]?.class || 'header-tag-blue'
			},
			goBack() {
				uni.navigateBack();
			},
			previewImage(index) {
				uni.previewImage({
					urls: this.images,
					current: this.images[index]
				});
			},
			share() {
				// 分享功能
				uni.showShareMenu({
					withShareTicket: true,
					menus: ['shareAppMessage', 'shareTimeline']
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.feedback-detail-container {
		min-height: 100vh;
		background: #f9fbfd;
		position: relative;
		/* 导航栏高度 */
	}

	/* 自定义导航栏 */
	.custom-navbar {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 88rpx;
		background: #fff;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 30rpx;
		box-sizing: border-box;
		z-index: 999;
		box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
	}

	.navbar-left,
	.navbar-right {
		width: 80rpx;
		height: 88rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.navbar-title {
		font-size: 32rpx;
		font-weight: 600;
		color: #333;
	}

	.iconfont {
		font-size: 36rpx;
		color: #333;
	}

	.detail-scroll {
		width: 100%;
		height: calc(100vh - 88rpx);
	}

	.detail-content {
		padding: 30rpx;
		background: #fff;
	}

	.header-info {
		display: flex;
		align-items: center;
		margin-bottom: 20rpx;
	}

	.header-tag {
		font-size: 24rpx;
		font-weight: 600;
		border-radius: 20rpx;
		padding: 6rpx 20rpx;
		color: #fff;
		margin-right: 20rpx;
	}

	.header-tag-blue {
		background: linear-gradient(90deg, #4e7fff 0%, #7db1ff 100%);
	}

	.header-tag-red {
		background: linear-gradient(90deg, #ff4e4e 0%, #ff7e7e 100%);
	}

	.header-tag-green {
		background: linear-gradient(90deg, #1ecb8b 0%, #7ee6b8 100%);
	}

	.header-tag-orange {
		background: linear-gradient(90deg, #ff8c00 0%, #ffb74d 100%);
	}

	.header-date {
		font-size: 24rpx;
		color: #999;
	}

	.content-title {
		font-size: 38rpx;
		font-weight: 600;
		color: #222;
		margin-bottom: 30rpx;
		line-height: 1.4;
	}

	.user-info {
		display: flex;
		align-items: center;
		margin-bottom: 30rpx;
	}

	.user-avatar {
		width: 80rpx;
		height: 80rpx;
		border-radius: 50%;
		margin-right: 20rpx;
	}

	.user-details {
		flex: 1;
	}

	.user-name {
		font-size: 28rpx;
		font-weight: 600;
		color: #333;
	}

	.user-company {
		font-size: 24rpx;
		color: #666;
		margin-top: 4rpx;
	}

	.money-tag {
		padding: 8rpx 16rpx;
		background: rgba(255, 78, 78, 0.1);
		border-radius: 20rpx;
		display: flex;
		align-items: center;
	}

	.money-icon {
		font-size: 24rpx;
		color: #ff4e4e;
		font-weight: bold;
		margin-right: 4rpx;
	}

	.money-value {
		font-size: 24rpx;
		color: #ff4e4e;
		font-weight: bold;
	}

	.content-desc {
		font-size: 28rpx;
		color: #333;
		line-height: 1.8;
		margin-bottom: 30rpx;
		text-align: justify;
	}

	/* 图片画廊 - 纵向排列 */
	.image-gallery {
		margin-bottom: 30rpx;
	}

	.image-item {
		margin-bottom: 20rpx;
		width: 100%;
		border-radius: 12rpx;
		overflow: hidden;
		background: #f5f7fa;
	}

	.gallery-image {
		width: 100%;
		display: block;
		border-radius: 12rpx;
	}

	.suggestion-section {
		background: #f7fafd;
		padding: 24rpx;
		border-radius: 16rpx;
		margin-bottom: 20rpx;
		margin-top: 20rpx;
	}

	.suggestion-title {
		display: flex;
		align-items: center;
		margin-bottom: 16rpx;
	}

	.suggestion-title text {
		font-size: 28rpx;
		font-weight: 600;
		color: #4e7fff;
		margin: 0 10rpx;
	}

	.suggestion-line {
		height: 2rpx;
		background: rgba(78, 127, 255, 0.2);
		flex: 1;
	}

	.suggestion-content {
		font-size: 26rpx;
		color: #555;
		line-height: 1.6;
	}

	.loading-container {
		display: flex;
		align-items: center;
		justify-content: center;
		height: 200rpx;
		width: 100%;
	}

	.loading-text {
		font-size: 28rpx;
		color: #999;
	}
</style>